package com.jic.market.request.rest.discountamount;

import com.jic.common.base.vo.AdminOperate;
import com.jic.market.request.rest.discount.PromotionGoods;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.ValidationException;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;

/**
 * @author yinhaijun
 * @date: 2020/4/16
 */
@Data
public class ShoppingCartDiscountAmountQueryRequest extends DiscountAmountBaseRequest implements Serializable {

    private static final long serialVersionUID = -8969884589726229212L;
    private AdminOperate adminOperate;

    @Valid
    @NotEmpty(message = "商品集合不能为空")
    @ApiModelProperty(notes = "商品集合", required = true)
    private List<PromotionGoods> promotionGoodsList;

    @ApiModelProperty(notes = "优惠劵", required = false)
    private List<String> couponCodeList;

    public void check(){
        if(null != promotionGoodsList && !promotionGoodsList.isEmpty()){
            promotionGoodsList.forEach(promotionGoods -> {
                Long num = promotionGoods.getNum();
                if(num == null || num <= 0L){
                    throw new ValidationException("商品数量必须大于0");
                }
            });
        }
    }
}
